<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/21
 * Time: 23:37
 */

namespace Lib\PayApi\Zftong;

use Lib\Utils\sha1\Signature;
use Lib\Utils\Utils;

class PaymentClient {
    public static function pay($orderNo, $money, $pbank) {
        $zftong = C('ZFTONG');

        // vendor('GuzzleHttp.Client');
        // vendor("HttpClient.guzzlehttp.guzzle.src.Client");
        // $http = new \GuzzleHttp\Client(['base_uri' => $zftong['baseUri'], 'timeout' => 60.0]);
        // $http = new Client(['base_uri' => $zftong['baseUri'], 'timeout' => 60.0]);

        $params = [
            "service" => $zftong['service'],
            "paymentType" => $zftong['paymentType'],
            "merchantId" => $zftong['merchantId'],
            "sellerEmail" => $zftong['sellerEmail'],
            "returnUrl" => $zftong['returnUrl'],
            "notifyUrl" => $zftong['notifyUrl'],
            "orderNo" => $orderNo,
            "title" => $zftong['title'],
            "body" => $zftong['body'],
            "totalFee" => $money,
            // "buyerEmail" => '4026739782@qq.com',
            "paymethod" => $zftong['paymethod'],
            "defaultbank" => $pbank,
            "isApp" => $zftong['isApp'],
            /*"appName" => 'test',
            "appMsg" => 'test',
            "appType" => 'wap',
            "userIp" => '127.0.0.1',
            "backUrl" => 'https://www.baidu.com/',*/
            "charset" => "UTF-8"
        ];

        $key = $zftong['apiKey'];
        $signature = new Signature($params, $key);

        $params['signType'] = $zftong['signType'];
        $params['sign'] = $signature->sign();

        return Utils::post($zftong['baseUri'].'/payment/v1/order/' . $params['merchantId'] . '-' . $params['orderNo'], $params);

        /*$response = $http->request('POST', '/payment/v1/order/' . $params['merchantId'] . '-' . $params['orderNo'], [
            'Content-Type' => 'text/xml; charset=UTF-8',
            'query' => $params
        ]);

        $body = $response->getBody();

        return [
            'code' => $response->getStatusCode(),
            'body' => $body
        ];*/
    }
}